<%@ page errorPage="../error.jsp" %>
<%@ page import = "java.io.*" %>
<%@ page import = "java.net.*" %>
<%@ page import = "java.text.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.net.URLEncoder" %>
<%@ page import="com.mbbcpa.app.dao.*" %>
<%@ page import="com.mbbcpa.util.*" %>
<%@ page import="com.mbbcpa.app.manager.*" %>
<%@ page import="com.mbbcpa.app.home.*" %>
<%
		//System.out.println("serachUser.jsp Start");
		boolean bDisplay = false;
        // get message if any
        String actionMsg = (String) request.getAttribute(Constants.ACTION_MSG_KEY);
        if (actionMsg == null)
    	    actionMsg="";
        UserDao usrD = new UserDao();

        usrD = (UserDao) request.getAttribute(Constants.USER_MAINTENANCE_LIST);
        if (usrD != null){
			if (usrD.getIsAccessAllow()){
				//System.out.println("serachUser.jsp Start 01");
				bDisplay = true;
			}else{
				actionMsg = usrD.getAccessReason();
			}
		}

		//System.out.println("serachUser.jsp Start 01");
		Properties paramProp = (Properties) session.getAttribute(Constants.PROPERTIES_PARAMETER);
		String userIdMaxLength = paramProp.getProperty(ParamHome.SEC_LOGIN_ID_MAX_LEN);

	//security access permission
		//System.out.println("serachUser.jsp Start 03");


	// Get the encryption key
	String encryKey = (String) session.getAttribute(Constants.ENCRYPTION_PASSPHRASE_KEY);

	// Logon user
	//SecUsersHome suh = SecUsersHome.getInstance();
	String logonUserId = (String) session.getAttribute(Constants.LOGINID);
	String merchantId = (String) session.getAttribute(Constants.MERCHANT_KEY);

	if (logonUserId == null || logonUserId.equals("") || merchantId == null || merchantId.equals("") ) {
		////System.out.println("null");
		request.getRequestDispatcher("/LogOut.do?dispatch=sessionExp").forward(request, response);
		return;
	}

		//System.out.println("serachUser.jsp Start 04");

%>

<%@ include file="../top.jsp" %>

<SCRIPT LANGUAGE="JavaScript1.2">
	function getUser(){
		strUserId = document.GetUserForm.searchUID.value;
		if(strUserId==null || strUserId==""){
			alert("Please Enter User Id !");
			return false;
		}
		document.GetUserForm.action='<%=response.encodeURL("UserSearch.do?dispatch=rsUserId")%>';
		document.GetUserForm.submit();
	}
</SCRIPT>
<body>
		<table align="center" border=1 width = 70%>
			<tr>
				<th class="pageTitle" colspan="2">Users Maintenance</th>
			</tr>
			<tr>
				<th class="header mbb_blue" colspan="2" align="left">Reset User</th>
			</tr>
			<%
			if(actionMsg != null)
			{
				if(!actionMsg.equals(""))
				{
			%>
				<th class="pageTitle" colspan="2"><%=actionMsg%></th>
			<%
				}
			}
			%>
			<tr class="header">
				<td colspan = "2"></td>
			</tr>
  		</table>

	<form name="GetUserForm" action="" method="post">
<% if (bDisplay ) { %>
		<table align="center" class="tabularData" width=70% border="0" rules="cols">
			<thead class="th1">
				<tr>
					<th colspan="6">
						<div class="sectionTableTitle">
							<h2>List of Users:</h2>
						</div>
					</th>
				</tr>
			</thead>

			<tr class="headerD" style="border: thin solid">
				<td width="15%" class="center_note_left">User ID</td>
				<td width="20%" class="center_note_left">User Name</td>
				<td width="15%" class="center_note_left">Role</td>
				<td width="10%" class="center_note_left">Enabled</td>
				<td width="10%" class="center_note_left">Locked</td>
				<td width="10%" class="center_note_left">Status</td>
<%
				String hrefLink="";
				String approveLink="";
				String rowClass="even";
				String createStatus="";
				// User enabled flag
				String userEnabled = usrD.getUserEnabled();

				if (userEnabled.equals(Constants.DB_YES)) {
					userEnabled = "Yes";
				} else if (userEnabled.equals(Constants.DB_NO)) {
					userEnabled = "No";
				} else if (userEnabled.equals(Constants.DB_FLAG_DORMANT)) {
					userEnabled = "Dormant";
				}

				hrefLink = "UserUpdate.do?dispatch=reset&" + Constants.PARAM_USER_ID + "="+ URLEncoder.encode(EncryptionHelper.encrypt(usrD.getUserLogin(), encryKey), Constants.UTF8_ENCODE);

				// create status
				if (usrD.getCreateStatus().equals(Constants.DB_USER_CREATE_NEW)) {
					createStatus = "New";
				} else if (usrD.getCreateStatus().equals(Constants.DB_USER_CREATE_APPROVE)) {
					createStatus = "Approved";
				}

%>
			</tr>
					<tr class ="<%=rowClass%>">
						<td width="15%" class="center_note_left">
					   		<a href="<%=hrefLink%>"><font color="#0033cc"><u>
					   		<%=usrD.getUserLogin()%>
					   		</u></font></a>
						</td>
						<td width="20%" class="center_note_left"><%=usrD.getUserName()%></td>
						<td width="15%" class="center_note_left"><%=usrD.getRoleName()%></td>
						<td width="10%" class="center_note_left"><%=userEnabled%></td>
						<td width="10%" class="center_note_left"><%=usrD.getUserLocked() ? "Yes" : "No" %></td>
						<td width="10%" class="center_note_left"><%=createStatus%></td>
					</tr>
		</table>

<% }else{	%>
		<table align="center" class="tabularData" width=70% border="0" rules="cols">
			<thead class="th1">
				<tr>
					<th colspan="8">
						<div class="sectionTableTitle">
							<h2>Enter User ID:</h2>
						</div>
					</th>
				</tr>
			</thead>
			<tr class="even">
				<td width="15%" class="center_note_right"><input type="text" name="searchUID" size=20 maxlength="<%=userIdMaxLength%>" autocomplete="off" value=""></td>
				<td width="20%" class="center_note_left"><input type="submit" name="Get User" value="Get User" onClick='getUser()'></td>
			</tr>
		</table>
<%	}	%>
	</form>

</body>

<%@ include file="../bottom.jsp" %>


